clear all
global eta
% Matrix for experimental sample

eta=[22,83,119,12,2
    8,58,143,23,3
	10,36,153,34,9
    8,42,137,45,11
    4,28,136,44,18];

n=size(eta,1);
eta=eta(:);
x0=ones(n^2,1)/n;
A=zeros(n*(n-1),n*n);
for i=1:n
    A(i*(n-1)-n+2:i*(n-1)-n+5,i*n-n+i)=-1;
    A(i*(n-1)-n+2:i*(n-1)-n+5,[1:i-1 i+1:n]+n*(i-1))=eye(n-1);
end
b=zeros(n*(n-1),1);
Aeq=repmat(eye(n),1,n);
beq=ones(n,1);
ub=ones(n*n,1);
o=optimset('MaxFunEvals',10000,'MaxIter',10000,'GradObj','on');
lb=ones(n*n,1)*1e-6;
[x,fval,exitflag,output,lambda] = fmincon('fun',x0,A,b,Aeq,beq,lb,ub,[],o)
theta=reshape(x,n,n)
dlmwrite('ML_Electricity_full.txt',theta,'delimiter','\t')
type('ML_Electricity_full.txt')